#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const int N = 110;
#define INF 0x3f3f3f3f;
typedef long long int ll;
#define close(); std::ios::sync_with_stdio(false);cin.tie(0),cout.tie(0);
//----------------------------------------------------------------------------//
ll n, a[N][N][N], st[N][N][N];
ll mx = 0;
int dx[] = { 1, -1, 0, 0, 0, 0 }, dy[] = { 0, 0, 1, -1, 0, 0 }, dz[] = { 0, 0, 0, 0, 1, -1 };
void dfs(int i, int j, int k, ll cur, ll sum)
{
    for(int f = 0; f < 6; f++)
    {
        // if(i + dx[f] >= 1 && i + dx[f] <= n && j + dy[f] >= 1 && j + dy[f] <= n && k + dz[f] >= 1 && k + dz[f] <= n)
        // {
        //     ll next = a[i + dx[f]][j + dy[f]][k + dz[f]];
        //     if(cur < next)
        //     {
        //         dfs(i + dx[f], j + dy[f], k + dz[f], next, sum + next);
        //     }
        // }
        ll next = a[i + dx[f]][j + dy[f]][k + dz[f]];
        if(cur < next)
        {
            dfs(i + dx[f], j + dy[f], k + dz[f], next, sum + 1);
        }
       
    }
    mx = max(sum, mx);
    return;
}

int main()
{
    close();
    cin >> n;

    for(int i = 1; i <= n; i++)
    {
        for(int j = 1; j <= n; j++)
        {
            for(int k = 1; k <= n; k++)
            {
                cin >> a[i][j][k];
            }
        }
    }

    for(int i = 1; i <= n; i++)
    {
        for(int j = 1; j <= n; j++)
        {
            for(int k = 1; k <= n; k++)
            {
                //memset(st, 0, sizeof st);
                //ll sum = a[i][j][k];
                ll cur = a[i][j][k];
                dfs(i, j, k, cur, 1);
            }
        }
    }

    cout << mx << '\n';



    return 0;
}